#define _CRT_SECURE_NO_WARNINGS

class Solution {
public:
    void reverseString(vector<char>& s) {
        reverse(s.begin(), s.end());
        return;
    }
};

class Solution {
public:
    void reverseString(vector<char>& s) {
        int left = 0;
        int right = s.size() - 1;
        while (left < right)
        {
            swap(s[left++], s[right--]);
        }
    }
};

class Solution {
public:
    string reverseStr(string s, int k) {
        for (int i = 0; i < s.size(); i += 2 * k)
        {
            int left = i;
            int right = i + k - 1;
            if (right > s.size() - 1)
                right = s.size() - 1;
            while (left < right)
            {
                swap(s[left++], s[right--]);
            }
        }
        return s;
    }
};

class Solution {
public:
    string replaceSpace(string s) {
        string ret;
        for (auto e : s)
        {
            if (e == ' ')
                ret += "%20";
            else
                ret += e;
        }
        return ret;
    }
};

class Solution {
public:
    void delSurBlk(string& s)
    {
        while (s[0] == ' ')
        {
            s.erase(s.begin());
        }
        while (s[s.size() - 1] == ' ')
        {
            s.erase(s.end() - 1);
        }
        for (int i = 0; i < s.size(); i++)
        {
            while (s[i] == ' ' && s[i - 1] == ' ')
                s.erase(s.begin() + i);
        }
    }

    string reverseWords(string s) {
        delSurBlk(s);
        reverse(s.begin(), s.end());
        int begin = 0, end = 0;
        while (end < s.size())
        {
            while (end < s.size() && s[end] != ' ')
                end++;
            reverse(s.begin() + begin, s.begin() + end);
            end++;
            begin = end;
        }
        return s;
    }
};

class Solution {
public:
    string reverseLeftWords(string s, int n) {
        reverse(s.begin(), s.end());
        reverse(s.begin(), s.begin() + (s.size() - n));
        reverse(s.begin() + (s.size() - n), s.end());
        return s;
    }
};